<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2015/12/28
 * Time: 12:26
 */

/**
 * Class Involved_ArticleModel
 */

class Involved_InformationModel extends BaseModel{

    protected $table = 'information';

    /**
     * 资讯列表
     * @author alice
     * @date 2016-1-19
     * @return mixed
     */
    public function ShowInformationList()
    {
        $info =  DB::table($this->table)->paginate(8);
        foreach($info as $k => $v)
        {
            $v->created = date('Y-m-d');
        }
        return $info;
    }

    /**
     * 资讯详情
     * @param $id
     * @author alice
     * @date 2016-1-19
     * @return mixed
     */
    public function ShowInformationInfo($id)
    {
        return  DB::table($this->table)->where('zx_id',$id)->first();
    }


    /**
     * 资讯列表
     * @param $paramObj
     * @return array
     * @author alice
     * @date 2016-2-16
     */
    public function GetInformationList($paramObj)
    {
        $offset = ($paramObj->page-1) * HostEnum::PAGE_NUM;

        $oQuery = DB::table($this->table);

        //分类查询
        $where = [];
        switch($paramObj->cate)
        {
            case "top_line";
                $where = ['cate'=> 100];
                break;
            case "culture";
                $where = ['cate'=> 101];
                break;
            case 'subject';
                $where = ['cate'=> 102];
                break;
            case 'trends';
                $where = ['cate'=> 103];
                break;
            default:
                break;
        }

        $oQuery->where($where);
        $list = $oQuery
            ->skip($offset)->take(HostEnum::PAGE_NUM)
            ->orderBy('zx_id','desc')
            ->get();

        return $list;

    }

    public function GetInformationDetail($id)
    {
        $info = DB::table($this->table)
            ->where(['zx_id' => $id])
            ->first();

        if (!empty($info)) {
            return $info;
        } else {
            throw new Exception('资讯不存在 ', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
    }

}